package com.sgb.kjwl.view.ui.activity.pick;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityPickRequireList3Binding;
import com.sgb.kjwl.di.pick.DaggerPickComponent;
import com.sgb.kjwl.di.pick.PickModule;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.view.ui.fragment.pick.PickRequireListFragment3;
import com.sgb.kjwl.viewmodel.pick.PickRequireListModel3;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.recyclerview.adapter.FragPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

public class PickRequireListActivity3 extends AppActivity {

    @Inject
    PickRequireListModel3 viewModel;
    private ActivityPickRequireList3Binding binding;
    private FragPagerAdapter pagerAdapter;
    private ArrayList<Fragment> mFragments;
    private String[] titles;

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerPickComponent.builder().appComponent(appComponent).pickModule(new PickModule(this)).build().inject(this);
    }

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, PickRequireListActivity3.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_pick_require_list3);
        binding.ivBack.setVisibility(View.VISIBLE);
        binding.ivBack.setOnClickListener(this);
    }

    @Override
    protected void init() {
        viewModel.getFilterTypeModel();
    }

    public void showTypeView(List<DictEntity3> datas) {
        if (datas == null || datas.size() == 0) {
            return;
        }
        mFragments = new ArrayList<>();
        int size = datas.size();
        titles = new String[size];
        for (int i = 0; i < size; i++) {
            mFragments.add(PickRequireListFragment3.newInstance(datas.get(i).getId(), datas.get(i).getName()));
            titles[i] = datas.get(i).getName();
        }
        pagerAdapter = new FragPagerAdapter(getSupportFragmentManager(), mFragments);
        binding.viewpager.setAdapter(pagerAdapter);
        binding.viewpager.setOffscreenPageLimit(titles.length - 1);
        binding.tablayout.setViewPager(binding.viewpager, titles);
    }

    public void changeType(int position) {
        binding.viewpager.setCurrentItem(position);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }

    }
}
